import type { ConfigEnv, UserConfig } from 'vite';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { pluginExposeRenderer } from './vite.base.config';

// https://vitejs.dev/config
export default defineConfig((env) => {
  const forgeEnv = env as ConfigEnv<'renderer'>;
  const { root, mode, forgeConfigSelf } = forgeEnv;
  const name = forgeConfigSelf.name ?? '';

  return {
    root: env.command === 'serve' ? 'node_modules/renderer' : root,

    //--- env
    mode,
    // envDir: '',
    // envPrefix: '',
    // define: {},

    resolve: {
      preserveSymlinks: env.command !== 'serve',
    },
    //--- public
    // publicDir: '',
    //--- assets
    // assetsInclude: '',
    base: './',
    //--- extensions
    // css: {},
    // json: {}
    // esbuild: {}

    //--- log
    // logLevel: ''
    // customerLogger: {}
    clearScreen: false,

    //--- plugins
    // html: {},
    plugins: [pluginExposeRenderer(name), vue()],
    server: {
      host: '192.168.20.212',
      // port: 5173,
      // strictPort: false,
      // https: {},
      // cors: {},
      // headers: {},
      // proxy: {},
      // hmr: {},
      // warmup: {},
      // watch: {},
      // middlewareMode: false,
      // fs: {},
      // origin: '',
      // sourcemapIgnoreList: false,
      // open: '',
    },
    build: {
      // copyPublicDir: true,
      // assetsInlineLimit(filePath, content) {},
      // assetsDir: '',
      // cssTarget: '',
      // cssCodeSplit: true,
      // cssMinify: '',
      // target: '',
      // terserOptions: {},
      // minify: 'esbuild',
      // modulePreload: { polyfill: true },
      // sourcemap: false,
      outDir: `.vite/renderer/${name}`,
      // write: true,
      // emptyOutDir: true,
      // watch: null,
      // commonjsOptions: {},
      // dynamicImportVarsOptions: {},
      // rollupOptions: {},
      // reportCompressedSize: true,
      // chunkSizeWarningLimit: 500,
    },
  } as UserConfig;
});
